/*
 * @FilePath: \VFD_GD32\BSP\inc\drv_vfd.h
 * @Description:
 *
 * Copyright (c) 2025 by ${w}, All Rights Reserved.
 */

#ifndef DRV_VFD_H_
#define DRV_VFD_H_

#define DIN(x)                                                                                 \
    do                                                                                         \
    {                                                                                          \
        x ? gpio_bit_write(GPIOA, GPIO_PIN_6, SET) : gpio_bit_write(GPIOA, GPIO_PIN_6, RESET); \
    } while (0)

#define CLK(x)                                                                                 \
    do                                                                                         \
    {                                                                                          \
        x ? gpio_bit_write(GPIOA, GPIO_PIN_5, SET) : gpio_bit_write(GPIOA, GPIO_PIN_5, RESET); \
    } while (0)

#define EN(x)                                                                                  \
    do                                                                                         \
    {                                                                                          \
        x ? gpio_bit_write(GPIOA, GPIO_PIN_7, SET) : gpio_bit_write(GPIOA, GPIO_PIN_7, RESET); \
    } while (0)

/* 用于缓存写入VFD屏的数据 */
extern uint32_t VFD_WRITE_BUFF[5];

/* 栅极 */
typedef enum
{
    G1 = 0,
    G2,
    G3,
    G4,
    G5
} eGrid_t;

extern eGrid_t eGrid;

#define VFD_GRID_ON 0x00
#define VFD_GRID_OFF 0x01

/* 前面3个栅格出来88外的段 */
#define VFD_G1_PBC_EN ENABLE
#define VFD_G1_PBC_CLR DISABLE
#define VFD_G1_MP3_EN ENABLE
#define VFD_G1_MP3_CLR DISABLE

#define VFD_G2_CON_EN ENABLE
#define VFD_G2_CON_CLR DISABLE
#define VFD_G2_DVD_EN ENABLE
#define VFD_G2_DVD_CLR DISABLE

#define VFD_G3_CON_EN ENABLE
#define VFD_G3_CON_CLR DISABLE
#define VFD_G3_DOD_EN ENABLE
#define VFD_G3_DOD_CLR DISABLE

void vfd_init(void);
void VFD_SendData(uint32_t buf);
uint32_t VFD_Show_Number_G1(uint8_t Number, uint8_t PBC_EN, uint8_t MP3_EN);
uint32_t VFD_Show_Number_G2_G3(uint8_t Number, uint8_t COLON_EN, uint8_t VD_D_EN);
void VFD_Display_Write_Buff(void);
void VFD_Full(uint8_t on_off);
void vfd_default(void);
void VFD_Display(void);

#endif // !DRV_VFD_H_
